<?php
/**
 * Created by PhpStorm.
 * User: kongdeqiang
 * Date: 2019/11/2
 * Time: 4:22 PM
 */
namespace App;
use EasySwoole\EasySwoole\Config;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use think\Template;
/**
 * 视图控制器基类
 * 有些功能没有完善
 */

class BaseController extends Controller
{

   function index()
   {
       // TODO: Implement index() method.
   }

    private $view;
    /**
     * 初始化模板引擎
     * ViewController constructor.
     * @param string   $actionName
     * @param Request  $request
     * @param Response $response
     */


    public function fetch($template=null, $vars = [])
    {
        ob_start();
        $template==null&&$template=$GLOBALS['base']['ACTION_NAME'];
        $this->view->fetch($template, $vars);
        $content = ob_get_clean();
        $this->response()->write($content);
    }

    public function init()
    {

        $tempPath               = Config::getInstance()->getConf('template');     # 临时文件目录
        $class_name_array       = explode('\\', static::class);
        $class_name_array_count = count($class_name_array);
        //$controller_path
          //  = $tempPath["view_path"].$class_name_array[$class_name_array_count - 1] . DIRECTORY_SEPARATOR;

        $controller_path
            = $tempPath["view_path"].$class_name_array[$class_name_array_count - 3] . DIRECTORY_SEPARATOR . $class_name_array[$class_name_array_count - 1] . DIRECTORY_SEPARATOR;

        $tempPath["view_path"] = $controller_path;
        $this->view  = new Template($tempPath);
    }

    public function assign(array $vars = []){
        $this->view->assign($vars);
    }






}